package com.tianya.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author TianYaGuoKe
 * @date 2025/5/4 12:56
 * @description 通用结果返回类
 */
@ApiModel(value = "通用结果返回类")
public class Results<T> {
    // 状态码
    @ApiModelProperty(value = "状态码")
    private int code;
    // 消息

    @ApiModelProperty(value = "消息")
    private String message;
    // 数据
    @ApiModelProperty(value = "数据")
    private T data = null;

    // 构造方法
    public Results(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 静态方法：成功返回
    public static <T> Results<T> success(T data) {
        return new Results<>(200, "操作成功", data);
    }
    public static <T> Results<T> success() {
        return new Results<>(200, "操作成功", null);
    }

    // 静态方法：失败返回
    public static <T> Results<T> error(int code, String message) {
        return new Results<>(code, message, null);
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}